objcinspect

package
v0.6.21 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package objcinspect provides Objective-C type encoding and signature string parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCxxTag

func IsCxxTag(name string) bool

IsCxxTag reports whether an aggregate tag has a spelling only C++ allows, such as a template argument list or a qualified name.

Types

type Kind

type Kind int

Kind represents the high-level category of an Objective-C type.

const (
	KindInvalid Kind = iota
	KindVoid
	KindId
	KindClass
	KindSEL
	KindBool
	KindChar
	KindUChar
	KindShort
	KindUShort
	KindInt
	KindUInt
	KindLong
	KindULong
	KindLongLong
	KindULongLong
	KindFloat
	KindDouble
	KindBitfield
	KindPointer
	KindArray
	KindStruct
	KindUnion
	KindBlock
	KindProtocol
	KindUnknown
)

func (Kind) String

func (k Kind) String() string

String returns a human-readable representation of Kind.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry stores known struct definitions indexed by struct tag name, allowing opaque struct references (e.g. "{CGRect=}") to be resolved to their fully defined field list and natural size when known.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty struct definition registry.

func (*Registry) Len

func (r *Registry) Len() int

Len returns the number of struct definitions held.

func (*Registry) Register

func (r *Registry) Register(t Type)

Register stores a struct definition. If t is a KindStruct with fields, it is saved under t.Name.

func (*Registry) RegisterEncoding

func (r *Registry) RegisterEncoding(encoding string) error

RegisterEncoding parses encoding and registers any defined struct within it.

func (*Registry) Resolve

func (r *Registry) Resolve(t Type) Type

Resolve returns a copy of t with any opaque struct references resolved using registered definitions.

type Signature

type Signature struct {
	Return Type
	Args   []Type
}

Signature represents a parsed Objective-C method or block signature.

func ParseBlockEncoding

func ParseBlockEncoding(encoding string) (Signature, error)

ParseBlockEncoding parses an extended or bare block type encoding. Bare block arguments appear as "@?", while extended block signatures appear as "@?<v@?I>" carrying inner return and argument types.

func ParseSignature

func ParseSignature(encoding string) (Signature, error)

ParseSignature parses an Objective-C method signature string. Standard method signatures include return type followed by argument types and stack offset numbers (e.g. "v24@0:8@16").

type Type

type Type struct {
	// Encoding is the type's own encoding, without the stack offset that
	// follows it in a method signature: parsing "@\"NSString\"16" yields
	// `@"NSString"`, not `@"NSString"16`. Callers match it against literals
	// and re-parse it, so a trailing offset would defeat both.
	Encoding  string
	Name      string
	FieldName string
	// HasQuote reports whether the field was written with a quoted name.
	// It is not redundant with FieldName != "": 522 encodings in the macOS
	// corpus carry an empty quoted field name (""), for example
	// `"__begin_"^@"__end_"^@""{?=...}`, so only HasQuote distinguishes an
	// unnamed field from a field named "".
	HasQuote bool
	IsAtomic bool
	Kind     Kind
	Elem     *Type  // Element type for pointer/array
	Fields   []Type // Struct/union fields
}

Type represents a parsed Objective-C type.

The parser does not record the qualifiers r, n, N, o, O, R and V: they are consumed and discarded, so a const-qualified type is indistinguishable from its unqualified form.

func ParseStruct

func ParseStruct(encoding string) (name string, fields []Type, naturalSize int, err error)

ParseStruct parses an Objective-C struct type encoding (e.g. "{CGPoint=dd}").

NOTE: Objective-C type encodings do NOT describe C struct packing, alignment, or padding bytes inserted by the C compiler. The naturalSize returned is calculated assuming natural alignment of each field. True memory layout and stride must be determined through C ABI rules or unsafe.Sizeof.

func (Type) Align

func (t Type) Align() int

Align returns the alignment requirement in bytes for the type.

func (Type) AlignRange

func (t Type) AlignRange() (lo, hi int)

AlignRange returns the least and greatest alignment, in bytes, that the type can have under the C declarations its encoding admits. The two differ only for an aggregate containing a bitfield: an encoding such as b8 records the field's width but not its declared type, and the declared type sets the alignment the field lends its aggregate. It returns 0, 0 if the layout cannot be determined.

func (Type) MemberSize

func (t Type) MemberSize(cxx bool) int

MemberSize is NaturalSize for t as a member of an aggregate. The flag cxx reports whether any enclosing aggregate is C++, as IsCxxTag detects. There, a member encoded with an empty member list, such as {Empty=}, is an empty class, which occupies one byte. In C an empty struct occupies none.

func (Type) NaturalSize

func (t Type) NaturalSize() int

NaturalSize returns the size in bytes of the type assuming natural alignment. It returns -1 if the size cannot be determined (e.g. for opaque struct references, unparseable fields, or bitfields whose layout depends on their declared type, which the encoding omits; see AlignRange). Returns 0 for empty structs.

Jump to

Keyboard shortcuts

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