var Debug … var ( CPUProfile … MemProfile … Trace … ) var IncludeTests … var Fix … // RegisterFlags registers command-line flags used by the analysis driver. func RegisterFlags() { … } // Run loads the packages specified by args using go/packages, // then applies the specified analyzers to them. // Analysis flags must already have been set. // Analyzers must be valid according to [analysis.Validate]. // It provides most of the logic for the main functions of both the // singlechecker and the multi-analysis commands. // It returns the appropriate exit code. func Run(args []string, analyzers []*analysis.Analyzer) (exitcode int) { … } // load loads the initial packages. Returns only top-level loading // errors. Does not consider errors in packages. func load(patterns []string, allSyntax bool) ([]*packages.Package, error) { … } // TestAnalyzer applies an analyzer to a set of packages (and their // dependencies if necessary) and returns the results. // The analyzer must be valid according to [analysis.Validate]. // // Facts about pkg are returned in a map keyed by object; package facts // have a nil key. // // This entry point is used only by analysistest. func TestAnalyzer(a *analysis.Analyzer, pkgs []*packages.Package) []*TestAnalyzerResult { … } type TestAnalyzerResult … func analyze(pkgs []*packages.Package, analyzers []*analysis.Analyzer) []*action { … } func applyFixes(roots []*action) error { … } // validateEdits returns a list of edits that is sorted and // contains no duplicate edits. Returns the index of some // overlapping adjacent edits if there is one and <0 if the // edits are valid. func validateEdits(edits []diff.Edit) ([]diff.Edit, int) { … } // diff3Conflict returns an error describing two conflicting sets of // edits on a file at path. func diff3Conflict(path string, xlabel, ylabel string, xedits, yedits []diff.Edit) error { … } // printDiagnostics prints the diagnostics for the root packages in either // plain text or JSON format. JSON format also includes errors for any // dependencies. // // It returns the exitcode: in plain mode, 0 for success, 1 for analysis // errors, and 3 for diagnostics. We avoid 2 since the flag package uses // it. JSON mode always succeeds at printing errors and diagnostics in a // structured form to stdout. func printDiagnostics(roots []*action) (exitcode int) { … } // needFacts reports whether any analysis required by the specified set // needs facts. If so, we must load the entire program from source. func needFacts(analyzers []*analysis.Analyzer) bool { … } type action … type objectFactKey … type packageFactKey … func (act *action) String() string { … } func execAll(actions []*action) { … } func (act *action) exec() { … } func (act *action) execOnce() { … } // inheritFacts populates act.facts with // those it obtains from its dependency, dep. func inheritFacts(act, dep *action) { … } // codeFact encodes then decodes a fact, // just to exercise that logic. func codeFact(fact analysis.Fact) (analysis.Fact, error) { … } // exportedFrom reports whether obj may be visible to a package that imports pkg. // This includes not just the exported members of pkg, but also unexported // constants, types, fields, and methods, perhaps belonging to other packages, // that find there way into the API. // This is an overapproximation of the more accurate approach used by // gc export data, which walks the type graph, but it's much simpler. // // TODO(adonovan): do more accurate filtering by walking the type graph. func exportedFrom(obj types.Object, pkg *types.Package) bool { … } // importObjectFact implements Pass.ImportObjectFact. // Given a non-nil pointer ptr of type *T, where *T satisfies Fact, // importObjectFact copies the fact value to *ptr. func (act *action) importObjectFact(obj types.Object, ptr analysis.Fact) bool { … } // exportObjectFact implements Pass.ExportObjectFact. func (act *action) exportObjectFact(obj types.Object, fact analysis.Fact) { … } // allObjectFacts implements Pass.AllObjectFacts. func (act *action) allObjectFacts() []analysis.ObjectFact { … } // importPackageFact implements Pass.ImportPackageFact. // Given a non-nil pointer ptr of type *T, where *T satisfies Fact, // fact copies the fact value to *ptr. func (act *action) importPackageFact(pkg *types.Package, ptr analysis.Fact) bool { … } // exportPackageFact implements Pass.ExportPackageFact. func (act *action) exportPackageFact(fact analysis.Fact) { … } func factType(fact analysis.Fact) reflect.Type { … } // allPackageFacts implements Pass.AllPackageFacts. func (act *action) allPackageFacts() []analysis.PackageFact { … } func dbg(b byte) bool { … }