naming

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package naming implements the lowered-name scheme: a lowered function keeps its method's own name when that name is unique in the package, falling back to the receiver-prefixed concatenation when it collides — the same discipline enum variant structs use. Visibility never widens: the name is exported iff BOTH the receiver type and the member are.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BareName added in v0.5.1

func BareName(owner, member string) string

BareName is the preferred lowered name: the member's own name, cased so the result is exported iff BOTH owner and member are exported.

(Stack).Map -> Map    (stack).Map -> map    (Stack).map -> map

func FieldName added in v0.2.0

func FieldName(paramName string, variantExported bool) string

FieldName computes the Go struct field name for a constructor parameter: capitalized iff the variant struct itself is exported (lowering never widens or narrows access).

func FuncName

func FuncName(recvType, method string, shared map[string]int) string

FuncName picks the lowered function name for a method: the bare method name when it is viable (not a keyword) and unshared in the package, the prefixed form otherwise. shared counts bare candidates across the package's lowered methods.

func MarkerMethodName added in v0.2.0

func MarkerMethodName(enumName string) string

MarkerMethodName is the sealed interface's marker method: always unexported, tied to the enum name.

func PrefixedName added in v0.5.1

func PrefixedName(owner, member string) string

PrefixedName is the collision fallback: concat(owner, Capitalize(member)), exported iff both are.

(Stack).Map -> StackMap    (stack).Map -> stackMap

func VariantTypeName added in v0.2.0

func VariantTypeName(enumName, variantName string, prefixed bool) string

VariantTypeName computes the lowered struct type name for an enum variant.

  • When the variant name is shared by multiple enums in the package (prefixed=true), the name is the concat of enum and variant names (OptionNone / listNone), disambiguating deterministically.
  • Otherwise the variant name is used directly, cased by the combined visibility rule: exported iff both the enum and the variant are exported.

Types

type Decl

type Decl struct {
	Name     string
	Position string
}

Decl is a package-scope identifier and where it was declared.

func TopLevelDecls

func TopLevelDecls(fset *token.FileSet, f *ast.File) []Decl

TopLevelDecls lists every package-scope identifier declared in a file (functions, types, vars, consts — not methods), for reserving authored names in a Table.

type Table

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

Table detects name collisions between generated functions and any other package-scope declaration (authored or generated).

func NewTable

func NewTable() *Table

func (*Table) AddAuthored

func (t *Table) AddAuthored(name, origin string)

AddAuthored records an existing package-scope identifier, e.g. AddAuthored("StackMap", "util.go:14:1"). Authored identifiers never collide with each other (go/types owns that); they only reserve names.

func (*Table) AddGenerated

func (t *Table) AddGenerated(name, origin string) error

AddGenerated records a generated function name, returning an error if the name is already taken by an authored declaration or another generated function. origin describes the method, e.g. `method (Stack[T]) Map[U] at stack.gpp:5:1`.

func (*Table) Has added in v0.5.1

func (t *Table) Has(name string) bool

Has reports whether a name is already reserved (authored or generated).

Jump to

Keyboard shortcuts

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