Documentation
¶
Overview ¶
Package loader loads a Go module once via go/packages and builds SSA for it. Nothing else in the program touches go/packages: every later phase works off the single *Program produced here.
Index ¶
- func FuncPackage(fn *ssa.Function) string
- type FileClass
- type Program
- func (p *Program) FuncClass(fn *ssa.Function) FileClass
- func (p *Program) GeneratedStats() (generated, total int)
- func (p *Program) IfCondition(pos token.Pos) (text string, stmtPos token.Pos, ok bool)
- func (p *Program) IfConditionOfBody(pos token.Pos) (text string, stmtPos token.Pos, ok bool)
- func (p *Program) InModule(fn *ssa.Function) bool
- func (p *Program) PkgInModule(pkg string) bool
- func (p *Program) Position(pos token.Pos) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FuncPackage ¶
FuncPackage returns the package path of fn, following Origin for generic instantiations and Parent for anonymous functions.
Types ¶
type FileClass ¶
type FileClass uint8
FileClass classifies a source file for pre-analysis exclusion. Generated and vendored files cannot be dropped at load time without breaking type-checking (a .pb.go file may define types that handwritten code uses), so they are classified immediately after load and excluded from every user-visible phase instead: entrypoint discovery, flow output, and stats.
type Program ¶
type Program struct {
Prog *ssa.Program
Pkgs []*packages.Package
Fset *token.FileSet
Module string // module path of the analyzed module
Dir string // absolute directory the module was loaded from
Warnings []string
// contains filtered or unexported fields
}
Program is the fully loaded and SSA-built analysis subject.
func Load ¶
Load loads the module rooted at dir and builds SSA with generic instantiation. Test files never load (Tests: false), so they cannot inflate any later phase.
func (*Program) FuncClass ¶
FuncClass reports the FileClass of the file declaring fn. Synthetic functions without a position (wrappers, bound methods) are Normal so they never mask real code they forward to.
func (*Program) GeneratedStats ¶
GeneratedStats counts module-local source functions by class, feeding the "most of your code is generated" honesty warning.
func (*Program) IfCondition ¶
IfCondition renders the source text of the if-statement enclosing pos (typically an ssa.If condition's position) and returns the statement's own position for deduplication: `&&`/`||` conditions lower to several SSA branches that all belong to one source `if`. Text is verbatim (including non-ASCII), single-line, capped for card display.
func (*Program) IfConditionOfBody ¶
IfConditionOfBody finds the If statement whose BODY (or else-branch) contains pos and renders its condition. Used for gates: their condition value (a phi, a stored bool) often carries no position inside the if, so the anchor comes from the first instruction of a branch instead. Walking outward and requiring pos inside Body/Else skips a nested if whose condition happens to open the branch.
func (*Program) PkgInModule ¶
PkgInModule reports whether a package path belongs to the analyzed module.