var typeNames … var output … var trimprefix … var linecomment … var buildTags … // Usage is a replacement usage function for the flags package. func Usage() { … } func main() { … } // baseName that will put the generated code together with pkg. func baseName(pkg *Package, typename string) string { … } // isDirectory reports whether the named file is a directory. func isDirectory(name string) bool { … } type Generator … func (g *Generator) Printf(format string, args ...interface{ … } type File … type Package … // loadPackages analyzes the single package constructed from the patterns and tags. // loadPackages exits if there is an error. // // Returns all variants (such as tests) of the package. // // logf is a test logging hook. It can be nil when not testing. func loadPackages( patterns, tags []string, trimPrefix string, lineComment bool, logf func(format string, args ...interface{ … } func findValues(typeName string, pkg *Package) []Value { … } // generate produces the String method for the named type. func (g *Generator) generate(typeName string, values []Value) { … } // splitIntoRuns breaks the values into runs of contiguous sequences. // For example, given 1,2,3,5,6,7 it returns {1,2,3},{5,6,7}. // The input slice is known to be non-empty. func splitIntoRuns(values []Value) [][]Value { … } // format returns the gofmt-ed contents of the Generator's buffer. func (g *Generator) format() []byte { … } type Value … func (v *Value) String() string { … } type byValue … func (b byValue) Len() int { … } func (b byValue) Swap(i, j int) { … } func (b byValue) Less(i, j int) bool { … } // genDecl processes one declaration clause. func (f *File) genDecl(node ast.Node) bool { … } // usize returns the number of bits of the smallest unsigned integer // type that will hold n. Used to create the smallest possible slice of // integers to use as indexes into the concatenated strings. func usize(n int) int { … } // declareIndexAndNameVars declares the index slices and concatenated names // strings representing the runs of values. func (g *Generator) declareIndexAndNameVars(runs [][]Value, typeName string) { … } // declareIndexAndNameVar is the single-run version of declareIndexAndNameVars func (g *Generator) declareIndexAndNameVar(run []Value, typeName string) { … } // createIndexAndNameDecl returns the pair of declarations for the run. The caller will add "const" and "var". func (g *Generator) createIndexAndNameDecl(run []Value, typeName string, suffix string) (string, string) { … } // declareNameVars declares the concatenated names string representing all the values in the runs. func (g *Generator) declareNameVars(runs [][]Value, typeName string, suffix string) { … } // buildOneRun generates the variables and String method for a single run of contiguous values. func (g *Generator) buildOneRun(runs [][]Value, typeName string) { … } const stringOneRun … const stringOneRunWithOffset … // buildMultipleRuns generates the variables and String method for multiple runs of contiguous values. // For this pattern, a single Printf format won't do. func (g *Generator) buildMultipleRuns(runs [][]Value, typeName string) { … } // buildMap handles the case where the space is so sparse a map is a reasonable fallback. // It's a rare situation but has simple code. func (g *Generator) buildMap(runs [][]Value, typeName string) { … } const stringMap …