view

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package view is the intermediate representation (IR) of a fully-resolved idiomatic framework package. It is pure data: every decision (type mapping, hierarchy, documentation, marshaling) is made by the gather phase and recorded here, and the render phase turns it into Go source through templates only.

view imports nothing from the rest of the emitter, so it cannot smuggle in resolution logic — the single-purpose split that keeps gather and render honest.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accessor added in v0.18.0

type Accessor struct {
	// GoName is the method name (e.g. "AsChunkSize").
	GoName string
	// Offset is the byte offset within the backing array.
	Offset int
	// GoType is the type a plain reinterpret accessor returns (empty for a
	// function-pointer accessor).
	GoType string
	// FuncType, when non-empty, is the Go func type ("func(unsafe.Pointer) int32")
	// a function-pointer accessor returns, bound via purego.RegisterFunc.
	FuncType string
	// Field is the original C field name, for the method's doc comment.
	Field string
}

Accessor is one generated `As<GoName>()` method over a byte offset of a ByteArrayStruct's backing array. When FuncType is empty it reinterprets the bytes as GoType (`return *(*GoType)(…)`); when FuncType is set the field is a C function pointer and the method binds the stored code pointer to that Go func type via purego.RegisterFunc.

type AsyncMethod

type AsyncMethod struct {
	// DocComment is the rendered doc comment block, or empty.
	DocComment string
	// Recv is the receiver clause "(x *Type) " or "" for a class function.
	Recv string
	// GoName is the exported Go method name.
	GoName string
	// ParamStr is the signature parameter list (always begins with
	// "ctx context.Context").
	ParamStr string
	// HasResult is true when the block carries one non-error value, so the
	// wrapper returns (ResultGoType, error) instead of plain error.
	HasResult bool
	// ResultGoType is the wrapped Go result type (set only when HasResult).
	ResultGoType string
	// ClosureParams are the completion block's Go parameter declarations, in
	// order (for example "_p0 objc.ID").
	ClosureParams []string
	// SendCall is the objc.Send expression that hands the block to Objective-C
	// (it references the local _block); an expression, not a declaration.
	SendCall string
	// ErrConvExpr is the right-hand side that converts the block's NSError
	// parameter to a Go error, or "" when the block has no error parameter.
	ErrConvExpr string
	// ResultConvExpr is the right-hand side that converts the block's result
	// parameter to ResultGoType (set only when HasResult).
	ResultConvExpr string
	// KeepAlive names the receiver and object-typed parameters kept alive until
	// the method returns (see Method.KeepAlive).
	KeepAlive []string
}

AsyncMethod is an Objective-C completion-handler method surfaced as a blocking, ctx-aware Go call. The completion block feeds a buffered channel of size 1 so it can always send and never leaks, and the outer function selects between the channel and ctx.Done. All marshaling expressions are resolved by gather; the template assembles the block and select with no string-built Go statements.

type BoolNSErrorMethod

type BoolNSErrorMethod struct {
	// DocComment is the rendered doc comment block, or empty.
	DocComment string
	// Recv is the receiver clause "(x *Type) " or "".
	Recv string
	// GoName is the exported Go method name.
	GoName string
	// RecvExpr is the object the Objective-C call is sent to.
	RecvExpr string
	// Selector is the Objective-C selector being sent.
	Selector string
	// MainThread runs the Objective-C call on the main thread (purego.Main) when
	// the selector is @MainActor-isolated.
	MainThread bool
	// KeepAlive names the receiver kept alive until the method returns (see
	// Method.KeepAlive).
	KeepAlive []string
}

BoolNSErrorMethod is an Objective-C method returning a success flag plus an NSError out-parameter, surfaced as a Go method that returns only error (nil on success).

type ByteArrayStruct added in v0.18.0

type ByteArrayStruct struct {
	// Doc is the one-line comment describing the struct; empty when none.
	Doc string
	// GoName is the exported struct type name.
	GoName string
	// Size is the total backing-array size in bytes (the authoritative C size).
	Size int
	// AlignElem, when non-empty, is the Go type of a leading zero-size field
	// (`_ [0]<AlignElem>`) that forces the backing struct's alignment to match C.
	// Empty for a packed struct (C alignment 1 = Go [N]byte alignment 1).
	AlignElem string
	// Accessors are the typed field views over the backing bytes.
	Accessors []Accessor
}

ByteArrayStruct is a value struct emitted as an aligned [Size]byte backing array plus typed accessor methods, for a C layout the clean typed-struct path cannot reproduce (packed-misaligned, unions) but whose exact size and field offsets are known. It is pointer/accessor-only — never passed by value.

type ConstKind

type ConstKind string

ConstKind says how a Constant accessor produces and types its value. It is a string so templates can compare against readable labels rather than opaque integers.

const (
	// ConstCFRef is a CoreFoundation reference value (const CF<T>Ref) returned as
	// an obj.Object.
	ConstCFRef ConstKind = "cfref"
	// ConstNSString is an NSString* global returned as the package-local *String
	// wrapper (Foundation only).
	ConstNSString ConstKind = "nsstring"
	// ConstObjcID is an NSString* global in a non-Foundation package, returned as
	// an obj.Object usable as a dictionary key or argument.
	ConstObjcID ConstKind = "objcid"
	// ConstObjcClass is a same-framework ObjC class pointer global returned as
	// the idiomatic wrapper type for that class.
	ConstObjcClass ConstKind = "objcclass"
	// ConstValue is a value-typed global (a scalar, enum, or value struct)
	// returned by dereferencing the symbol's address.
	ConstValue ConstKind = "value"
	// ConstRawAddr is a global whose type could not be expressed; its raw symbol
	// address is returned as a uintptr (matching the raw layer's degrade).
	ConstRawAddr ConstKind = "rawaddr"
)

type Constant

type Constant struct {
	// GoName is the exported Go accessor name.
	GoName string
	// ExternName is the underlying framework symbol whose address is read.
	ExternName string
	// CommentBlock is the rendered doc comment (already "// …\n"), or empty.
	CommentBlock string
	// Kind selects how the symbol's value is produced and typed.
	Kind ConstKind
	// GoTypeName is the resolved Go return type: the wrapper type name for
	// ConstObjcClass, or the value type (a scalar, enum, or value struct) for
	// ConstValue.
	GoTypeName string
	// Zero is the zero-value literal returned when the symbol is missing; set only
	// for ConstValue (e.g. "0", "corefoundation.CGPoint{}").
	Zero string
}

Constant is a global constant value re-emitted as an idiomatic accessor function. The gather phase resolves which Kind the symbol's value is produced as; the constant template renders the matching accessor.

type Delegate added in v0.16.0

type Delegate struct {
	// DocComment is the rendered doc comment for the interface type.
	DocComment string
	// IfaceName is the Go interface name (VirtualMachineDelegate).
	IfaceName string
	// ProtocolName is the Objective-C protocol (VZVirtualMachineDelegate).
	ProtocolName string
	// ShimClassName is the runtime-registered Objective-C class name; globally
	// unique (GoShimVirtualizationVirtualMachineDelegate).
	ShimClassName string
	// ShimFuncName is the unexported builder that wraps a Go value
	// (newVirtualMachineDelegateShim).
	ShimFuncName string
	// ClassVar is the package-level variable base holding the registered class
	// and its sync.Once (_virtualMachineDelegateShimClass).
	ClassVar string
	// Required are the protocol's required methods — the interface's method
	// set. Optional are the @optional methods, each carried by its own
	// one-method upgrade interface.
	Required []DelegateMethod
	Optional []DelegateMethod
}

Delegate is one Objective-C delegate protocol surfaced as a Go interface plus the shim builder that lets a plain Go value act as that delegate. The gather phase (protocols.go) resolves every name, signature, and conversion expression; the delegate template renders the interface declarations, the once-registered shim class, and the wrap function with no string-built Go.

type DelegateMethod added in v0.16.0

type DelegateMethod struct {
	// DocComment is the rendered doc line(s) for the interface method (already
	// "// "-prefixed, trailing newline), or empty.
	DocComment string
	// OptionalDoc is the rendered doc comment for an optional method's upgrade
	// interface type (empty for required methods).
	OptionalDoc string
	// OptIfaceName is the one-method upgrade interface for an optional method
	// (VirtualMachineDelegateGuestDidStopHandler); empty for required methods.
	OptIfaceName string
	// GoName is the Go method name.
	GoName string
	// Selector is the Objective-C selector this method answers.
	Selector string
	// SigParams is the Go interface signature parameter list.
	SigParams string
	// RetSig is the Go return clause (" bool", "" for void).
	RetSig string
	// AssertIface is the interface the callback type-asserts shim.Value to —
	// the delegate interface for required methods, OptIfaceName for optional.
	AssertIface string
	// ABIParams are the callback's parameter declarations after (self, _cmd),
	// in order ("_p0 objc.ID", "_p1 int").
	ABIParams []string
	// ABIRet is the callback's return type ("" for void).
	ABIRet string
	// CallArgs are the converted argument expressions passed to the Go method,
	// parallel to the interface signature.
	CallArgs []string
	// RetExpr converts the Go method call's result into the callback's return
	// value (set only when RetSig is non-empty); it embeds the full
	// _h.<GoName>(…) call.
	RetExpr string
	// RetZero is the callback's zero return when the Go value does not
	// implement the method (set only when RetSig is non-empty).
	RetZero string
}

DelegateMethod is one bridgeable protocol method: its Go interface signature, and the pieces of the Objective-C callback that routes the invocation to the Go value.

type Dispatch

type Dispatch struct {
	// Guards are pre-call statements rendered first as early returns or panics
	// (for example a bounds check before an index accessor); empty for most
	// methods.
	Guards []string
	// Call is the Objective-C call expression, already marshaled
	// (objc.Send[T](recv, sel, args…)); it is an expression, not a declaration.
	Call string
	// Error is true when the selector took a trailing NSError**: the body then
	// emits the `if _nsErr != 0` early return and a trailing nil on success.
	Error bool
	// RetKind selects how Call's result is converted back to Go.
	RetKind RetKind
	// RetWrap is the conversion expression for an object/array result, with one
	// %s placeholder for the raw result pointer (empty for other kinds).
	RetWrap string
	// RetZero is the zero literal returned on the error path before the error
	// (empty for void).
	RetZero string
	// Outs are value out-parameters lifted from the signature into extra return
	// values, in declaration order.
	Outs []DispatchOut
}

Dispatch is the resolved body of a plain method or package-level function: the marshaled Objective-C call expression plus how its result, trailing NSError, and value out-parameters become Go return values. The gather phase makes every decision; the method_body / dispatch_tail template renders the statements with iteration and conditionals only — it never decides a type.

type DispatchOut

type DispatchOut struct {
	// GoName is the local variable / return name.
	GoName string
	// GoType is the out-parameter's Go type.
	GoType string
	// Zero is the type's zero literal for the error-path return.
	Zero string
}

DispatchOut is one value out-parameter, declared as a local whose address is passed to the call and whose value is returned alongside the method's result.

type Enum

type Enum struct {
	// GoName is the de-prefixed exported Go type name (VZVirtualMachineState ->
	// VirtualMachineState).
	GoName string
	// GoType is the underlying integer type (for example int64 or uint).
	GoType string
	// IsBitmask is true when the values are option flags meant to be combined
	// with |, which selects the bitwise String rendering.
	IsBitmask bool
	// CommentBlock is the fully-rendered doc + deprecation comment for the type,
	// already prefixed with "// " on every line (empty when undocumented).
	CommentBlock string
	// Members are the enum constants in declaration order, deduplicated by
	// (name, value); they populate the const block.
	Members []EnumMember
	// UniqueMembers are the members deduplicated by value alone; they populate
	// the non-bitmask String switch so two names for one value do not produce a
	// duplicate case.
	UniqueMembers []EnumMember
	// DefaultFmt is the fmt verb string for the String default branch (for
	// example "VirtualMachineState(%d)").
	DefaultFmt string
}

Enum is a named Objective-C enumeration re-emitted as a concrete Go type (a `type X <underlying>` declaration with a typed const block and a String method), not an alias to the raw bindings. Every naming, dedup, and comment decision is already made by the gather phase and recorded here; the render phase turns it into Go source through the enum template alone.

type EnumMember

type EnumMember struct {
	// ConstName is the de-prefixed exported constant name.
	ConstName string
	// Value is the integer value as a Go literal string.
	Value string
	// CommentBlock is the rendered doc + deprecation comment for the member,
	// indented inside the const block (empty when undocumented).
	CommentBlock string
	// IsZeroVal is true when Value is "0"; the bitmask String rendering skips
	// zero-valued members because they contribute no flag bit.
	IsZeroVal bool
}

EnumMember is one constant of an Enum.

type ErrorSentinel

type ErrorSentinel struct {
	// GoName is the exported sentinel variable name (for example ErrInternalError).
	GoName string
	// CommentBlock is the rendered doc comment (already "// …\n").
	CommentBlock string
	// Domain is the NSError domain string the framework reports.
	Domain string
	// Code is the integer error code as a Go literal string.
	Code string
}

ErrorSentinel is a named error value for one member of a framework's error-code enum, so callers can match a returned error with errors.Is.

type Field

type Field struct {
	// GoName is the exported field name.
	GoName string
	// GoType is the field's resolved Go type (a primitive or another value
	// struct in the same package).
	GoType string
}

Field is one field of a value Struct.

type Func

type Func struct {
	// GoName is the exported Go function name.
	GoName string
	// CName is the underlying C symbol bound via RegisterLibFunc.
	CName string
	// VarName is the package-level bound-function variable (for example _fnFoo).
	VarName string
	// CommentLine is the rendered doc comment line (already "// …\n").
	CommentLine string
	// CommentFirst places CommentLine before the bound-function variable rather
	// than before the func declaration. The CFErrorRef wrappers document the var;
	// the generic and OSStatus wrappers document the func.
	CommentFirst bool
	// ABIParams are the C ABI parameter types for the bound-function variable.
	ABIParams []string
	// ABIRet is the C ABI return type ("" for void).
	ABIRet string
	// SigParams are the Go signature parameters ("name Type").
	SigParams []string
	// RetSig is the Go return clause, including a leading space when non-empty
	// (" error", " (obj.Object, error)", " int", "").
	RetSig string
	// Kind selects the body tail.
	Kind FuncKind
	// PreLines are statements emitted after the bind prologue and before the call
	// (out-parameter declarations, or a CFErrorRef holder).
	PreLines []string
	// Call is the bound-function call expression (for example _fnFoo(a, b)).
	Call string
	// Wrap is the object-result conversion template (one %s); used by FuncObject.
	Wrap string
	// Outs are pointer out-parameters lifted from the signature into extra return
	// values, in declaration order. When non-empty the body renders var decls for
	// each, passes &local to the call, and returns the function's own result (per
	// Kind) followed by each out value; RetSig is then the parenthesised tuple.
	Outs []DispatchOut
	// FailRet is the error-path return list for FuncOSStatus and FuncStatusCode.
	FailRet string
	// OkRet is the success return list for FuncOSStatus and FuncStatusCode.
	OkRet string
	// Fail is the failure condition for FuncCFErrorBool (for example "!_ok").
	Fail string
	// ErrExpr converts the bound call's status-code result (_rc) into a Go
	// error for FuncStatusCode (for example
	// errkit.FromCode("HypervisorReturnDomain", int64(_rc), 0)).
	ErrExpr string
}

Func is a C-function wrapper: a lazily-bound Go function over a framework C symbol. Every wrapper shares a prologue (a package-level bound-function variable and a one-time RegisterLibFunc) and differs only in how the result and any error are produced, which Kind selects. The gather phase resolves all expressions; the cfunc template renders the body with no string-built Go.

type FuncKind

type FuncKind int

FuncKind selects how a Func wrapper turns its bound call into a Go result.

const (
	// FuncVoid discards the result.
	FuncVoid FuncKind = iota
	// FuncString converts a non-nil result pointer to a Go string.
	FuncString
	// FuncObject wraps the result pointer via Wrap.
	FuncObject
	// FuncScalar returns the raw result.
	FuncScalar
	// FuncOSStatus turns an OSStatus return into a Go error.
	FuncOSStatus
	// FuncCFErrorBool turns a BOOL + CFErrorRef out-parameter into a Go error.
	FuncCFErrorBool
	// FuncCFErrorPtr turns a pointer return + CFErrorRef out-parameter into
	// (obj.Object, error).
	FuncCFErrorPtr
	// FuncStatusCode turns a registered status-code typedef return (for example
	// hv_return_t) into a Go error via ErrExpr, returning any lifted
	// out-parameters on success. Registered through the idiomatic.json sidecar's
	// error_typedefs.
	FuncStatusCode
)

type HandleType added in v0.18.0

type HandleType struct {
	// Doc is the one-line comment describing the handle type; empty when none.
	Doc string
	// GoName is the exported handle type name (e.g. "CFArrayRef").
	GoName string
	// ImmutableType, when non-empty, is the immutable counterpart type name of a
	// CFMutable<X>Ref handle (e.g. "CFArrayRef" for "CFMutableArrayRef"); the
	// generated ImmutableMethod converts to it. In C a mutable ref IS-A immutable
	// ref, a subtyping the distinct Go types lose, so this restores the widening.
	ImmutableType string
	// ImmutableMethod is the conversion method name (e.g. "AsArray").
	ImmutableMethod string
}

HandleType is a distinct named handle type the idiomatic layer emits for an opaque CoreFoundation / handle typedef: `type CFArrayRef struct{ obj.Object }`. It embeds obj.Object (so it still satisfies Object and carries the lifecycle methods) while being its own Go type, giving callers the compile-time type distinction a generic obj.Object cannot. Its zero value wraps no object; the generated IsNil method reports that NULL state.

type Method

type Method struct {
	// DocComment is the fully-rendered doc comment block (already "// "-prefixed,
	// trailing newline), or empty when undocumented.
	DocComment string
	// Recv is the receiver clause "(x *Type) " for an instance method, or "" for
	// a package-level class function.
	Recv string
	// GoName is the exported Go method name.
	GoName string
	// ParamStr is the rendered signature parameter list (out-parameters omitted).
	ParamStr string
	// RetSig is the rendered return clause: "", " T", or " (T, error)".
	RetSig string
	// Dispatch is the method body (call + result/error/out-parameter handling).
	Dispatch Dispatch

	// MainThread is set when the underlying selector is @MainActor-isolated: the
	// template runs the body on the main thread via purego.Main. The body
	// sub-template is reused verbatim — it is lifted into an inner closure whose
	// results are captured into RetVars (declared with RetTypes) and returned.
	MainThread bool
	// RetVars are the names of the captured-return locals ("_mainthread0", …),
	// one per return value; empty for a void method. Parallel to RetTypes.
	RetVars []string
	// RetTypes are the Go types of each captured-return local, parallel to
	// RetVars, used only to declare them before the purego.Main call.
	RetTypes []string

	// KeepAlive names the receiver and object-typed parameters whose wrappers
	// must outlive the Objective-C call: their pointer is read before the send,
	// and without a keep-alive the collector could finalize (and release) the
	// object mid-call. The template renders one defer runtime.KeepAlive per
	// name at the top of the body.
	KeepAlive []string
}

Method is a resolved Go method (or package-level function) that calls a single Objective-C method. The signature pieces are pre-rendered by the gather phase; the body is described by Dispatch and rendered by the method template alone.

type Protocol added in v0.17.0

type Protocol struct {
	// Doc is the one-line interface comment; empty when none.
	Doc string
	// GoName is the exported Go interface name.
	GoName string
	// Methods are the interface methods (name + full signature).
	Methods []ProtocolMethod
}

Protocol is an Objective-C protocol re-emitted as a Go interface — the idiomatic duck-typed counterpart of the raw layer's protocol interface. A Go value satisfies it by declaring the listed methods.

type ProtocolMethod added in v0.17.0

type ProtocolMethod struct {
	// GoName is the exported method name.
	GoName string
	// Signature is the method's parenthesised parameter list plus return clause,
	// e.g. "(index uint) obj.Object".
	Signature string
}

ProtocolMethod is one method of a Protocol interface.

type RetKind

type RetKind int

RetKind says how a Dispatch result pointer is turned into the Go return value.

const (
	// RetVoid is a method with no value return (error may still be present).
	RetVoid RetKind = iota
	// RetScalar returns the raw result unchanged (scalar, bool, or enum).
	RetScalar
	// RetString converts the result to a Go string with a nil-pointer guard.
	RetString
	// RetObject wraps the result pointer via RetWrap (an object or a slice).
	RetObject
)

type SliceMethod

type SliceMethod struct {
	// DocComment is the rendered doc comment block, or empty.
	DocComment string
	// Recv is the receiver clause "(x *Type) " or "".
	Recv string
	// GoName is the exported Go method name.
	GoName string
	// RecvExpr is the object the Objective-C call is sent to.
	RecvExpr string
	// Selector is the Objective-C selector being sent.
	Selector string
	// ElemGoType is the slice element's Go type.
	ElemGoType string
	// HasError is true when the underlying getter reports an NSError, so the
	// wrapper returns ([]T, error).
	HasError bool
	// ConvClosure is the per-element conversion closure expression
	// (func(_id objc.ID) T { return … }).
	ConvClosure string
	// MainThread runs the Objective-C call on the main thread (purego.Main) when
	// the selector is @MainActor-isolated.
	MainThread bool
	// KeepAlive names the receiver kept alive until the method returns (see
	// Method.KeepAlive).
	KeepAlive []string
}

SliceMethod is an Objective-C array-returning getter surfaced as a Go method that returns a slice, converting each element with ConvClosure.

type Struct

type Struct struct {
	// GoName is the exported Go type name.
	GoName string
	// Doc is the documentation prose, already cleaned of HeaderDoc/Doxygen tags;
	// empty when the symbol has no documentation.
	Doc string
	// Fields are the struct's fields, in declaration order.
	Fields []Field
	// IsOpaque marks a struct the C headers declare with no members (e.g. NSZone).
	// It renders as `struct{}`, matching the raw layer, so callers can still name
	// and pass a pointer to it. A struct whose members all happen to be skipped
	// (private bitfields) is NOT opaque — it renders with an empty body.
	IsOpaque bool
}

Struct is a value-type struct re-emitted in an idiomatic package (for example CGRect, CGPoint, NSRange). It is passed to Objective-C by value, so the field names, Go types, and order match what the framework expects.

type TypedefAlias added in v0.17.0

type TypedefAlias struct {
	// Doc is the one-line comment describing the alias; empty when none.
	Doc string
	// GoName is the exported alias name.
	GoName string
	// RHS is the aliased type expression.
	RHS string
}

TypedefAlias is a Go type alias re-emitted for a C typedef (e.g. NSRect = CGRect, or the opaque-pointer form Id = *ObjcObject), so callers can name the alias through the idiomatic package. RHS is the fully-resolved right-hand side, already localized to a hermetic type (a same-package type or a sibling idiomatic package's).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL