Documentation
¶
Overview ¶
Package naming converts ObjC identifiers to idiomatic Go names.
ObjC uses a keyword-argument selector syntax ("objectAtIndex:") that must be flattened into a single Go method name ("ObjectAtIndex"). This package provides the mapping functions used consistently across all emitters:
- MethodName converts an ObjC selector string to an exported Go method name, handling common suffixes ("UsingBlock:" → drop "Block") and acronym casing.
- ParamName lowercases the first letter of a parameter name and escapes any identifier that collides with a Go keyword or common builtin.
- PackageName lowercases the framework name to produce the Go package name ("Foundation" → "foundation").
- BridgeFuncName produces the C symbol for a bridge function ("foundation_NSArray_objectAtIndex_").
- ProtocolGoTypeName disambiguates protocol names from same-named classes (NSObject class vs NSObjectProtocol interface).
Index ¶
- Variables
- func BlockTypeName(className, selector string) string
- func BridgeFuncName(framework, className, selector string, isClassMethod bool) string
- func FindSiblingMethod(methods []macosplatformmetadata.Method, selector string, isClassMethod bool) (macosplatformmetadata.Method, bool)
- func FunctionBridgeID(framework, funcName string) string
- func IsIBActionSender(objcType string) bool
- func MethodBridgeID(framework, class, selector string, isClassMethod bool) string
- func ParamName(objcName string) string
- func ResolveGoMethodName(gn string, method macosplatformmetadata.Method, ...) (resolved string, skip bool)
Constants ¶
This section is empty.
Variables ¶
var ( MethodName = core.MethodName PackageName = core.PackageName GoTypeName = core.GoTypeName ProtocolGoTypeName = core.ProtocolGoTypeName ExportedFunctionName = core.ExportedFunctionName ExportedTypeName = core.ExportedTypeName )
Shared naming helpers (identical across the purego/cgo pipelines) live in internal/codegen/naming/core and are re-exported here. This is also where the libraries pipeline gains ExportedFunctionName / ExportedTypeName (previously frameworks-only), so library type names can be unified onto the PascalCase ExportedTypeName form (audit_token_t → AuditTokenT) instead of the underscore-preserving GoTypeName.
Functions ¶
func BlockTypeName ¶
BlockTypeName produces a named Go type for an ObjC block used in a framework. Example: ("Foundation", "NSArray", "enumerateObjectsUsingBlock:") → "NSArrayEnumerationBlock"
func BridgeFuncName ¶
BridgeFuncName produces the C bridge function name for a given class+selector. Class methods get a "_cls" suffix to avoid conflicts with identically-named instance methods (e.g. +[NSDate timeIntervalSinceReferenceDate] vs -[NSDate timeIntervalSinceReferenceDate]).
("Foundation", "NSArray", "objectAtIndex:", false) → "foundation_NSArray_objectAtIndex"
("Foundation", "NSBundle", "URLForAuxiliaryExecutable:", false) → "foundation_NSBundle_urlForAuxiliaryExecutable"
("Foundation", "NSDate", "timeIntervalSinceReferenceDate", true) → "foundation_NSDate_timeIntervalSinceReferenceDate_cls"
func FindSiblingMethod ¶
func FindSiblingMethod(methods []macosplatformmetadata.Method, selector string, isClassMethod bool) (macosplatformmetadata.Method, bool)
FindSiblingMethod returns the first method in methods that matches both selector and isClassMethod. Used to locate the zero-arg counterpart when classifying a one-arg method under disambiguation rules 1 and 2.
func FunctionBridgeID ¶
FunctionBridgeID returns the structured-path ID comment for a free C function binding.
("CoreFoundation", "CFArrayCreateMutable") → "ID: objc-sym CoreFoundation.CFArrayCreateMutable"
func IsIBActionSender ¶
IsIBActionSender reports whether an ObjC type string is the bare `id` sender type used exclusively in Interface Builder action wiring.
func MethodBridgeID ¶
MethodBridgeID returns the structured-path ID comment for an ObjC method binding.
("Foundation", "NSArray", "objectAtIndex:", false) → "ID: objc-sym Foundation.NSArray.-[objectAtIndex:]"
("Foundation", "NSDate", "date", true) → "ID: objc-sym Foundation.NSDate.+[date]"
func ParamName ¶
ParamName sanitises an ObjC parameter name for use as a Go argument name. It lowercases the first letter and escapes Go reserved words.
func ResolveGoMethodName ¶
func ResolveGoMethodName(gn string, method macosplatformmetadata.Method, classMethods []macosplatformmetadata.Method, goNameCount map[string]int) (resolved string, skip bool)
ResolveGoMethodName resolves the final Go name for a method when its base name (from MethodName) collides with another method on the same class (goNameCount[gn] > 1).
Three rules in priority order:
Zero-arg priority: the zero-arg form (-[Foo bar]) owns the clean base name. The one-arg overload (-[Foo bar:]) is resolved by rules 2 or 3. Rationale: in Cocoa the zero-arg form is always the direct programmatic call; any n-arg overload is a specialisation.
IBAction omission: a one-arg method whose sole argument is the bare `id` type AND whose zero-arg sibling exists is a Cocoa IBAction overload used only by Interface Builder — never from code. Returns skip=true so the caller omits the method entirely. Example: -[WKWebView goBack:(id)sender] vs -[WKWebView goBack]
Last resort — genuine selector collision: two ObjC selectors produce the same Go name (e.g. transformContextForBox: and transformContext:forBox:). The colon count is appended for a deterministic, stable suffix.
Class methods are excluded from rules 1–2 because they occupy a separate Go namespace (ClassName-prefixed package-level functions). The rare collision between two class methods falls directly to rule 3.
Types ¶
This section is empty.