Documentation
¶
Overview ¶
Package common holds structalign's public contracts: the interfaces that decouple the CLI's layers and the plain data types those interfaces traffic in. Implementations live under internal/. Keeping the contracts here (rather than internal/) lets mockery generate mocks from a non-internal source.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorizeStrings ¶ added in v0.6.0
func ColorizeStrings() []string
ColorizeStrings returns a slice of all String values of the enum
func DiffStyleStrings ¶
func DiffStyleStrings() []string
DiffStyleStrings returns a slice of all String values of the enum
func FormatStrings ¶ added in v0.7.0
func FormatStrings() []string
FormatStrings returns a slice of all String values of the enum
Types ¶
type Colorize ¶ added in v0.6.0
type Colorize uint8
Colorize selects when colored output is emitted. enumer generates its String/parse/text-marshal helpers, a flag.Value implementation (Set), and a Type method for usage strings, see colorize_enumer.go; the names map to "auto"/"always"/"never" via -trimprefix=Colorize -transform=lower.
func ColorizeString ¶ added in v0.6.0
ColorizeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func ColorizeValues ¶ added in v0.6.0
func ColorizeValues() []Colorize
ColorizeValues returns all values of the enum
func (Colorize) IsAColorize ¶ added in v0.6.0
IsAColorize returns "true" if the value is listed in the enum definition. "false" otherwise
func (Colorize) MarshalText ¶ added in v0.6.0
MarshalText implements the encoding.TextMarshaler interface for Colorize
func (*Colorize) Set ¶ added in v0.6.0
Set allows flag and pflag libraries to set a value dynamically.
func (Colorize) Type ¶ added in v0.6.0
Type returns a string that represents all possible values to this type joined by '|'.
func (*Colorize) UnmarshalText ¶ added in v0.6.0
UnmarshalText implements the encoding.TextUnmarshaler interface for Colorize
type DiffStyle ¶
type DiffStyle uint8
DiffStyle selects how a Finding is rendered. enumer generates its String/parse/text-marshal helpers, a flag.Value implementation (Set), and a Type method for usage strings, see diffstyle_enumer.go; the names map to "unified"/"side"/"none" via -trimprefix=Diff -transform=lower.
func DiffStyleString ¶
DiffStyleString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func DiffStyleValues ¶
func DiffStyleValues() []DiffStyle
DiffStyleValues returns all values of the enum
func (DiffStyle) IsADiffStyle ¶
IsADiffStyle returns "true" if the value is listed in the enum definition. "false" otherwise
func (DiffStyle) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for DiffStyle
func (DiffStyle) Type ¶ added in v0.6.0
Type returns a string that represents all possible values to this type joined by '|'.
func (*DiffStyle) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for DiffStyle
type Finding ¶
type Finding struct {
// Package is the name of the package containing the finding.
Package string
// Fset is the FileSet used to decode the Pos location into file, line, and column.
Fset *token.FileSet
// Pos is the position of the struct declaration.
Pos token.Pos
// Name is the enclosing named type name, or an empty string for an anonymous struct.
Name string
// TypeParams represents the type-parameter names for a generic type, e.g. "[T]" (else empty).
TypeParams string
// Message is the high-level human-readable size comparison diagnostic.
Message string
// Original is the original struct source code representation (e.g. "struct{...}").
Original string
// Proposed is the reordered struct source code from the analyzer's suggested fix.
Proposed string
// OldSize is the original struct size in bytes.
OldSize int64
// NewSize is the proposed (reordered) struct size in bytes.
NewSize int64
}
Finding is one struct whose fields could be reordered to use less memory.
type Format ¶ added in v0.7.0
type Format uint8
Format selects the output presentation style. enumer generates its String/parse/text-marshal helpers, a flag.Value implementation (Set), and a Type method for usage strings, see format_enumer.go; the names map to "text"/"json" via -trimprefix=Format -transform=lower.
func FormatString ¶ added in v0.7.0
FormatString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func FormatValues ¶ added in v0.7.0
func FormatValues() []Format
FormatValues returns all values of the enum
func (Format) IsAFormat ¶ added in v0.7.0
IsAFormat returns "true" if the value is listed in the enum definition. "false" otherwise
func (Format) MarshalText ¶ added in v0.7.0
MarshalText implements the encoding.TextMarshaler interface for Format
func (*Format) Set ¶ added in v0.7.0
Set allows flag and pflag libraries to set a value dynamically.
func (Format) Type ¶ added in v0.7.0
Type returns a string that represents all possible values to this type joined by '|'.
func (*Format) UnmarshalText ¶ added in v0.7.0
UnmarshalText implements the encoding.TextUnmarshaler interface for Format
type Inspector ¶
Inspector computes the memory layout of each named struct in a Target, controlled by opts.
type Layout ¶
type Layout struct {
// Package is the name of the package declaring the struct.
Package string
// Name is the name of the struct type.
Name string
// TypeParams represents the type parameters for a generic type, e.g. "[T]" (else empty).
TypeParams string
// Note is an optional message warning or disclaimer regarding the layout details.
Note string
// Total is the total size of the struct in bytes, including padding.
Total int64
// Align is the alignment requirement of the struct in bytes.
Align int64
// Padding is the sum of all padding bytes within the struct.
Padding int64
// Fields lists the struct's fields in memory-layout order.
Fields []LayoutField
}
Layout is one named struct's computed memory layout.
type LayoutField ¶
type LayoutField struct {
// Name is the name of the struct field.
Name string
// Type is the type of the field represented as a string.
Type string
// Tag is the raw struct field tag (excluding surrounding backticks), or empty if none exists.
Tag string
// Assume is the assumed type parameter(s) for a generic field, e.g. "T=any", or empty if none exists.
Assume string
// Offset is the byte offset of the field within the struct layout.
Offset int64
// Size is the size of the field's type in bytes.
Size int64
// Align is the alignment of the field's type in bytes.
Align int64
// Padding is the trailing padding in bytes inserted after this field.
Padding int64
}
LayoutField is one field's place in a struct's memory layout.
type Loader ¶
Loader resolves Go package patterns (./..., import paths, directories, and "file=" queries) into typed Targets.
type Options ¶ added in v0.4.0
type Options struct {
Patterns []string // -type globs matched against named-type names (nil = all)
KeepTags bool // preserve struct field tags in rendered text
IncludeGenerated bool // analyze structs in generated files (default: skip them)
SkipCachePadded bool // skip structs containing a golang.org/x/sys/cpu.CacheLinePad field
RespectNolint bool // suppress findings on types carrying a recognized //nolint directive
NolintLinters []string // named //nolint tokens that trigger suppression (bare //nolint always counts)
}
Options controls which structs are analyzed and how findings are produced.
type Sizes ¶
type Sizes interface {
Sizeof(t types.Type) int64
Alignof(t types.Type) int64
Offsetsof(fields []*types.Var) []int64
}
Sizes abstracts go/types sizing so the target architecture is injectable: a real types.Sizes in production, a fixed types.SizesFor("gc","amd64") in tests (making golden output deterministic on any host arch). Its method set matches go/types.Sizes, so a common.Sizes value is directly assignable to a types.Sizes (e.g. analysis.Pass.TypesSizes).
type Target ¶
type Target struct {
// PkgPath is the full Go package import path (e.g., "github.com/peczenyj/structalign/pkg/common").
PkgPath string
// Fset is the FileSet used to resolve AST positions within this package.
Fset *token.FileSet
// Syntax is the parsed AST slice representing all Go source files in the package.
Syntax []*ast.File
// Types is the type system package representation containing scopes and type definitions.
Types *types.Package
// TypesInfo contains the type-checker's AST-to-type associations, definitions, and uses.
TypesInfo *types.Info
// Sizes provides the target-architecture specific type sizing logic.
Sizes Sizes
// Errors lists any syntax or type-checking errors encountered during package loading.
Errors []error
}
Target is a loader-agnostic view of one typed Go package: everything the analyzer and the layout inspector need, without exposing go/packages.Package.