Documentation ¶
Overview ¶
Package modifier implements modifier-based code generation for cff directives.
Index ¶
Constants ¶
const ( // TaskName is the prefix for the name that replaces a cff.Task. TaskName = "_cffTask" // ResultsName is the prefix for the name that replaces a cff.Results. ResultsName = "_cffResults" // ParamsName is the prefix for the name that replaces a cff.Params. ParamsName = "_cffParams" // WithEmitterName is the prefix for the name that replaces a cff.WithEmitter. WithEmitterName = "_cffWithEmitter" // InstrumentFlowName is the prefix for the name that replaces a cff.InstrumentFlow. InstrumentFlowName = "_cffInstrumentFlow" )
const (
// TmplDir is the path pattern for modifier templates.
TmplDir = "templates/*"
)
Variables ¶
var ModifierTmplFS embed.FS
ModifierTmplFS embeds templates for generating modifier implementations.
Functions ¶
func TrimFilename ¶
TrimFilename is a utility function used for trimming just the file name without ".go" suffix to guarantee uniqueness of generated cff functions.
Types ¶
type GenParams ¶
GenParams is the parameter for Modifiers to generate the body of their corresponding methods.
type Modifier ¶
type Modifier interface { Expr() ast.Expr // The ast Expr that produced this modifier. FuncExpr() string // The name of the modifier-generated function. Provides() []ast.Expr // The expressions that are provided to and returned by this modifier function. GenImpl(p GenParams) error // Generates the function body of the modifier-generated function. }
Modifier changes the existing code by doing two things.
- It generates a function that corresponds to what the cff "API"s do by inspecting the arguments.
- It inline replaces the cff "API" call with calls to corrresponding generated function.
Each call to cff "API" is translates to a modifier.
func NewConcurrencyModifier ¶
NewConcurrencyModifier returns a Modifier that corresponds to a cff.Concurrency call.
func NewModifier ¶
NewModifier creates a basic modifier from the arguments of a cff directive.
func Placeholder ¶
Placeholder constructs a placeholder modifier that will be incrementally replaced by real modifier implementations. This should be removed when all modifiers are implemented.
type Params ¶
type Params struct { // Name prefix that will replace the modified cff directive in generated // code. Name string // Modified is the ast.Expr that is replaced by the modifier. Modified ast.Expr // Provided are arguments of modified cff directive. These values are the // same as the values returned by the replacement modifier function. Provided []ast.Expr Fset *token.FileSet Info *types.Info }
Params are the inputs to generating a modifier function.