Documentation
¶
Overview ¶
Package ssax holds small shared helpers for inspecting SSA values and call sites: callee identification, best-effort string-constant resolution, and variadic-argument extraction. Used by entrypoint discovery and effect detection.
Index ¶
- func ConcreteMethod(prog *ssa.Program, v ssa.Value, name string) *ssa.Function
- func ConstString(v ssa.Value) (string, bool)
- func Declared(prog *ssa.Program, fn *ssa.Function) *ssa.Function
- func FieldStore(fa *ssa.FieldAddr) ssa.Value
- func FuncDisplayName(fn *ssa.Function) string
- func IsErrorType(t types.Type) bool
- func NormalizePkg(path string) string
- func ReachingStore(load *ssa.UnOp, addr ssa.Value) ssa.Value
- func ResolveFuncValue(v ssa.Value) *ssa.Function
- func SentinelErrors(fn *ssa.Function) []string
- func SingleStore(addr ssa.Value) ssa.Value
- func SliceStrings(v ssa.Value) ([]string, bool)
- func StructFieldString(v ssa.Value, field string) (string, bool)
- func TrimModule(name, module string) string
- func VarargValues(v ssa.Value) []ssa.Value
- type CalleeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConcreteMethod ¶
ConcreteMethod finds the named method on the concrete type behind an interface-typed value (the operand of its MakeInterface), e.g. the ServeHTTP of a handler passed to http.Handle.
func ConstString ¶
ConstString resolves v to a string constant if it is one, a conversion of one, or a package-level variable stored exactly once (in init) with one. Returns "", false when the value is dynamic.
func Declared ¶
Declared maps synthetic wrappers (indirection/promotion/bound wrappers) to the declared function they forward to.
func FieldStore ¶ added in v0.2.0
FieldStore is packageFieldStore for callers outside this package: the value stored into the struct field fa addresses, when exactly one such store exists program-wide. It resolves the field a constructor assigned once, for values that reach a call site through a struct rather than a local.
func FuncDisplayName ¶
FuncDisplayName returns the stable qualified name of fn, using the generic origin so instantiations do not multiply identities.
func IsErrorType ¶
func NormalizePkg ¶
NormalizePkg strips a trailing /vN major-version suffix so matchers cover all major versions of a library with one entry.
func ReachingStore ¶
ReachingStore finds the store to addr nearest before the load, walking backwards through the load's block and then through single-predecessor blocks. Sound for the return-site pattern (store result; maybe rundefers; load result; return); gives up on merges rather than guessing.
func ResolveFuncValue ¶
ResolveFuncValue chases a function-typed value to its *ssa.Function: direct references, closures, and conversions such as http.HandlerFunc(f).
func SentinelErrors ¶
SentinelErrors reports the named error outcomes fn can return: sentinel globals (return nil, ErrOrderNotFound), methods chained on sentinel globals (errs.OrderNotFound.WithDetails(...)), and constant errors.New / fmt.Errorf messages. Propagated errors from callees are deliberately ignored - they surface on the callee's own node. These are the business branch points a flow reader cares about.
func SingleStore ¶
SingleStore returns the value stored to addr if exactly one store to it exists in the enclosing function (for locals/field addresses) or in the package init (for globals). Returns nil otherwise.
func SliceStrings ¶
SliceStrings resolves a []string-typed value built from constants (either a vararg pack or a literal) to its elements. ok is false if any element is dynamic.
func StructFieldString ¶
StructFieldString resolves the named field of a struct-typed value to a string constant. It handles the common composite-literal shape: a load of an *ssa.Alloc whose FieldAddrs were stored exactly once. This is how Kafka writer/reader topics configured via config structs resolve.
func TrimModule ¶
TrimModule shortens a qualified function name relative to a module path: "(*example.com/m/svc.Service).Create" -> "(*svc.Service).Create".
Types ¶
type CalleeInfo ¶
type CalleeInfo struct {
Pkg string // package path of the callee (or its interface)
Type string // receiver or interface type name, "" for package funcs
Name string // function or method name
Invoke bool // true for interface dispatch
Static *ssa.Function // non-nil for statically resolved callees
// ArgOffset is the index of the first non-receiver argument in
// site.Common().Args.
ArgOffset int
}
CalleeInfo identifies what a call site calls, uniformly for static calls and interface (invoke-mode) calls.
func Callee ¶
func Callee(site ssa.CallInstruction) *CalleeInfo
Callee extracts CalleeInfo from a call site. Returns nil for calls to builtins and for dynamic calls of function values.