generate

Imports

Imports #

"bufio"
"bytes"
"context"
"fmt"
"go/parser"
"go/token"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/modload"
"cmd/go/internal/str"
"cmd/go/internal/work"
"cmd/internal/pathcache"

Constants & Variables

CmdGenerate var #

var CmdGenerate = *ast.UnaryExpr

generateRunFlag var #

var generateRunFlag string

generateRunRE var #

var generateRunRE *regexp.Regexp

generateSkipFlag var #

var generateSkipFlag string

generateSkipRE var #

var generateSkipRE *regexp.Regexp

stop var #

var stop = *ast.CallExpr

Structs

Generator struct #

A Generator represents the state of a single Go source file being scanned for generator commands.

type Generator struct {
r io.Reader
path string
dir string
file string
pkg string
commands map[string][]string
lineNum int
env []string
}

Functions

errorf method #

errorf logs an error message prefixed with the file and line number. It then exits the program (with exit status 1) because generation stops at the first error.

func (g *Generator) errorf(format string, args ...any)

exec method #

exec runs the command specified by the argument. The first word is the command name itself.

func (g *Generator) exec(words []string)

expandVar method #

expandVar expands the $XXX invocation in word. It is called by os.Expand.

func (g *Generator) expandVar(word string) string

generate function #

generate runs the generation directives for a single file.

func generate(absFile string) bool

init function #

func init()

isGoGenerate function #

func isGoGenerate(buf []byte) bool

run method #

run runs the generators in the current file.

func (g *Generator) run() (ok bool)

runGenerate function #

func runGenerate(ctx context.Context, cmd *base.Command, args []string)

setEnv method #

setEnv sets the extra environment variables used when executing a single go:generate command.

func (g *Generator) setEnv()

setShorthand method #

setShorthand installs a new shorthand as defined by a -command directive.

func (g *Generator) setShorthand(words []string)

split method #

split breaks the line into words, evaluating quoted strings and evaluating environment variables. The initial //go:generate element is present in line.

func (g *Generator) split(line string) []string

Generated with Arrow