Help us shape the future of Go! Take the 2026 Go Developer Survey

view

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package view holds the pure-data intermediate representation for the raw purego framework emitter. A gather phase in package emit resolves metadata and type information into these structs; package render turns them into Go source through templates only. No struct here carries behaviour or makes a type decision — every value is already resolved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockAdapter

type BlockAdapter struct {
	// Degraded marks an unbridgeable block: no construction is emitted.
	Degraded bool
	// ParamName is the public closure parameter name (the Go func the caller
	// supplies).
	ParamName string
	// BlockVar is the local objc.Block variable ("__block_<ParamName>").
	BlockVar string
	// CallbackSig is the fully-rendered objc.NewBlock callback signature,
	// e.g. "func(_ objc.Block, blockParam0 objc.ID) bool".
	CallbackSig string
	// Params are the callback's adapted parameters, in order, used to emit the
	// retain guards for ObjC-object arguments.
	Params []BlockCallbackParam
	// HasReturn is true when the block returns a value (the call is returned).
	HasReturn bool
	// CallExpr is the call into the public closure with each ABI value converted
	// to its public form, e.g. "onDone(purego.GoCString(blockParam0))".
	CallExpr string
}

BlockAdapter is the resolved objc.NewBlock construction for one block-typed parameter of a wrapper function or method. A degraded adapter emits nothing (the public objc.Block parameter is passed through verbatim); otherwise the template builds a block whose callback adapts the ABI values to the public Go closure and invokes it.

type BlockCallbackParam

type BlockCallbackParam struct {
	// ArgName is the callback parameter name ("blockParam<i>").
	ArgName string
	// NeedsRetain marks an ObjC-object argument that must be retained before it
	// is wrapped, so the Go finalizer owns the +1.
	NeedsRetain bool
}

BlockCallbackParam is one parameter of a block callback, used to emit the pre-call retain guard for ObjC-object arguments.

type ClassSelectorVar

type ClassSelectorVar struct {
	// VarName is the unexported selector variable name.
	VarName string
	// Selector is the ObjC selector string passed to objc.RegisterName.
	Selector string
}

ClassSelectorVar is one registered-selector variable in a class's var block.

type ClassTypeDecl

type ClassTypeDecl struct {
	// CommentBlock is the class doc, the Apple documentation URL, and any
	// deprecation line (all column 0, trailing newline).
	CommentBlock string
	// TypeHeader is the type name with any generic constraint list,
	// e.g. "NSView" or "NSArray[ObjectType objc.AnyObject]".
	TypeHeader string
	// EmbedLine is the struct's single line: "ptr objc.ID" for a root or
	// cycle-broken class, otherwise the embedded superclass type.
	EmbedLine string
	// EmitPtrMethods emits the promoted Ptr()/InitPtr() accessors (only for
	// root/cycle-broken classes that hold the ptr field directly).
	EmitPtrMethods bool
	// PtrReceiver is the receiver type for the Ptr/InitPtr methods, with any
	// generic parameter list, e.g. "NSView" or "NSArray[ObjectType]".
	PtrReceiver string
}

ClassTypeDecl is the resolved Go struct declaration for an ObjC class: the doc comment block, the (possibly generic) type header, the single embedded field (the raw ptr for a root/cycle-broken class, otherwise the superclass struct), and — for those root/cycle-broken classes — the promoted Ptr/InitPtr methods.

type ClassVars

type ClassVars struct {
	// ClassVarName is the unexported class-reference variable (e.g. "_clsNSView").
	ClassVarName string
	// ClassName is the ObjC class name passed to _objcClass.
	ClassName string
	// Selectors are the registered-selector variables, deduplicated by name; an
	// empty list collapses to a single `var` declaration.
	Selectors []ClassSelectorVar
}

ClassVars is the resolved package-level var block for a class: the class reference variable and one registered-selector variable per selector used by the class's methods.

type Enum

type Enum struct {
	// GoName is the exported Go type name (empty for an anonymous enum).
	GoName string
	// GoType is the underlying Go integer type (empty for an anonymous enum).
	GoType string
	// CommentBlock is the rendered doc + deprecation comment for the type, each
	// line "// "-prefixed with a trailing newline, or empty.
	CommentBlock string
	// IsBitmask selects the flag-combining String form over the switch form.
	IsBitmask bool
	// IsAnon marks an anonymous enum: only Members is used, rendered as an
	// untyped const block.
	IsAnon bool
	// HasConstBlock is true when the named enum had at least one (deduplicated)
	// member, so a `const (...)` block is emitted even if every member was
	// filtered out as unavailable — matching the original emitter exactly.
	HasConstBlock bool
	// Members are the constant declarations, in source order, already
	// deduplicated and filtered to available members.
	Members []EnumMember
	// StringMembers are the members the String method dispatches on: for the
	// switch form, deduplicated by value; for the bitmask form, the non-zero
	// members. Empty for an anonymous enum.
	StringMembers []EnumMember
}

Enum is a resolved ObjC enum ready to render as a Go type. A named enum emits a `type X <underlying>` declaration, a typed const block, and a String method; an anonymous enum (IsAnon) emits only an untyped const block.

type EnumMember

type EnumMember struct {
	// ConstName is the exported Go constant name.
	ConstName string
	// Value is the literal integer value as it appears in source.
	Value string
	// CommentBlock is the rendered doc comment for the member ("\t// …\n"), or
	// empty.
	CommentBlock string
}

EnumMember is one constant of an enum.

type Extern

type Extern struct {
	// CommentBlock is the doc + deprecation comment (column 0, trailing newline).
	CommentBlock string
	// GoName is the exported accessor function name.
	GoName string
	// RetType is the accessor's Go return type ("uintptr" for the raw form).
	RetType string
	// DylibVar is the package-level variable holding the loaded dylib handle.
	DylibVar string
	// Symbol is the C symbol name passed to Dlsym.
	Symbol string
	// Form selects the body shape (see above).
	Form string
	// GoType is the value type read for the "value" form.
	GoType string
	// FromIDCall is the typed-wrapper expression for the "fromid" form.
	FromIDCall string
	// Zero is the zero value returned by the "value" form when the symbol is
	// absent.
	Zero string
}

Extern is a resolved accessor for an extern global symbol, read at runtime via purego.Dlsym. The Form selects the body shape:

  • "raw" — returns the raw uintptr address
  • "fromid" — reads an ObjC object reference and wraps it via FromIDCall
  • "string" — reads a char* as a Go string
  • "value" — reads a value type, returning Zero when the symbol is absent

type FromIDConstructor

type FromIDConstructor struct {
	// Signature is the full function signature up to the opening brace, e.g.
	// "func NSViewFromID(id objc.ID) *NSView" or the generic form.
	Signature string
	// AllocType is the type literal allocated for the wrapper, e.g. "NSView" or
	// "NSArray[ObjectType]".
	AllocType string
}

FromIDConstructor is the resolved XFromID factory: it wraps a raw objc.ID in the class's Go type and registers it with the runtime for finalization.

type Function

type Function struct {
	// CommentBlock is the doc, "// C function: <name>", and deprecation comment
	// (all column 0, trailing newline).
	CommentBlock string
	GoName       string
	ParamStr     string
	RetSig       string
	// Adapters build the objc.Block values for block-typed parameters.
	Adapters []BlockAdapter
	// FuncVarName is the bound C function-pointer variable.
	FuncVarName string
	// CallStr is the comma-joined call argument list.
	CallStr string
	// ReturnKind selects the body shape: 0 void, 1 plain return, 2 object
	// return (retain then wrap).
	ReturnKind int
	// WrapExpr is the wrapper expression for an object return (ReturnKind 2).
	WrapExpr string
}

Function is an exported wrapper around a C function pointer. Block-typed parameters are adapted by Adapters before the call; the result is returned directly, returned after a retain (object returns), or discarded (void).

type FunctionFile

type FunctionFile struct {
	Vars     []FunctionVar
	Wrappers []Function
}

FunctionFile is the whole rendered functions output for a package: the `var (...)` block of purego-bound C function pointers followed by the exported wrapper functions.

type FunctionVar

type FunctionVar struct {
	CommentBlock string
	VarName      string
	FuncType     string
}

FunctionVar is one entry in the function-pointer var block: the binding variable and its C-ABI func type. Its CommentBlock matches the original emitter's indentation (the doc line is tab-indented inside the var block; a deprecation line is at column 0 and gofmt re-indents it).

type Protocol

type Protocol struct {
	// CommentBlock is the "// X wraps the ObjC protocol Y." comment (column 0,
	// trailing newline).
	CommentBlock string
	// GoName is the exported Go interface name.
	GoName string
	// Embeds are the embedded parent interface names, already qualified with a
	// package selector when cross-framework.
	Embeds []string
	// Methods are the required interface methods.
	Methods []ProtocolMethod
}

Protocol is a resolved ObjC protocol rendered as a Go interface: the embedded parent interfaces followed by the required method set.

type ProtocolMethod

type ProtocolMethod struct {
	GoName    string
	Signature string
}

ProtocolMethod is one method of a protocol interface: its Go name and its already-resolved signature (the "(params) ret" fragment).

type RawMethod

type RawMethod struct {
	// CommentBlock is the doc + deprecation comment (column 0, trailing newline).
	CommentBlock string
	// Receiver is the method receiver clause "(o *Type) " (empty for a class
	// function).
	Receiver string
	// GoName is the exported method or function name.
	GoName string
	// ParamStr is the rendered signature parameter list.
	ParamStr string
	// ReturnSig is the return clause: "", " T", " error", or " (T, error)".
	ReturnSig string
	// Adapters build objc.Block values for block-typed parameters.
	Adapters []BlockAdapter
	// HasNSError adds the trailing NSError out-parameter and error handling.
	HasNSError bool
	// Target is the receiver expression of the objc.Send ("o.Ptr()" or the class
	// reference for class methods).
	Target string
	// SelVar is the registered-selector variable passed to objc.Send.
	SelVar string
	// SendArgStr is the marshaled argument list, already comma-prefixed (or empty).
	SendArgStr string
	// ReturnKind selects the dispatch shape: 0 void, 1 object, 2 string, 3 bool,
	// 4 scalar/struct.
	ReturnKind int
	// RetGoType is the Go return type (the objc.Send type parameter for the
	// scalar/struct kind).
	RetGoType string
	// AlreadyRetained skips the post-call retain for object returns the callee
	// already retained (NARC).
	AlreadyRetained bool
	// WrapExpr wraps the raw objc.ID result for an object return (kind 1).
	WrapExpr string
	// ZeroVal is the zero value returned on the error path for a scalar/struct
	// return (kind 4 with NSError).
	ZeroVal string
	// MainThread wraps the objc.Send dispatch in purego.Main so the call runs on
	// the main thread — set when the class or selector is @MainActor-isolated
	// (and the selector is not nonisolated). Mirrors the idiomatic layer.
	MainThread bool
	// RetDecls are the `var _mainthreadN T` declarations hoisted above the
	// purego.Main closure so return values can escape it (empty for a void
	// main-thread method).
	RetDecls []RawRetVar
	// RetVarList is the comma-joined `_mainthread0, _mainthread1` list used for
	// the in-closure assignment and the trailing return (empty for void).
	RetVarList string
}

RawMethod is a resolved Go method (or class function) wrapping an ObjC method via objc.Send. Block parameters are adapted first; the call dispatches on the resolved return kind, optionally unpacking a trailing NSError.

type RawRetVar

type RawRetVar struct {
	Name string
	Type string
}

RawRetVar is one hoisted return variable for a main-thread-wrapped method.

type Struct

type Struct struct {
	// CommentBlock is everything rendered before the `type` keyword — the doc
	// comment, any deprecation line, the "// C struct: <name>" note, and (for an
	// opaque struct) the "// X is an opaque type." line — each "// "-prefixed
	// with a trailing newline. Already at column 0, matching the original.
	CommentBlock string
	// GoName is the exported Go type name.
	GoName string
	// IsOpaque marks a zero-field struct, rendered as `struct{}`.
	IsOpaque bool
	// Fields are the exported fields, in declaration order (empty when opaque).
	Fields []StructField
}

Struct is a resolved C/ObjC struct ready to render as a Go type. A struct with no fields renders as an opaque empty struct; otherwise it renders its exported fields with their resolved Go types.

type StructField

type StructField struct {
	GoName string
	GoType string
}

StructField is one exported struct field with its resolved Go type.

type TypedefAlias

type TypedefAlias struct {
	// CommentBlock is the doc comment before the alias (column 0, trailing
	// newline).
	CommentBlock string
	// GoName is the exported alias name.
	GoName string
	// RHS is the right-hand side of the alias: a type, or "*Type" for an
	// opaque-pointer typedef.
	RHS string
}

TypedefAlias is a resolved C typedef rendered as a Go type alias (`type X = <RHS>`), for example `NSRect = CGRect` or an opaque-pointer `FooRef = *Foo`.

Jump to

Keyboard shortcuts

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