Documentation ¶
Overview ¶
Package codegen contains shared utilities for generating code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertStructUnchanged ¶
func AssertStructUnchanged(t *types.Struct, thisPkg *types.Package, tname, ctx string, imports map[string]struct{}) []byte
AssertStructUnchanged generates code that asserts at compile time that type t is unchanged. thisPkg is the package containing t. tname is the named type corresponding to t. ctx is a single-word context for this assertion, such as "Clone". If non-nil, AssertStructUnchanged will add elements to imports for each package path that the caller must import for the returned code to compile.
func ContainsPointers ¶
ContainsPointers reports whether typ contains any pointers, either explicitly or implicitly. It has special handling for some types that contain pointers that we know are free from memory aliasing/mutation concerns.
func NamedTypes ¶
NamedTypes returns all named types in pkg, keyed by their type name.
func WriteFormatted ¶
WriteFormatted writes code to path. It runs gofmt on it before writing; if gofmt fails, it writes code unchanged. Errors can include I/O errors and gofmt errors.
The advantage of always writing code to path, even if gofmt fails, is that it makes debugging easier. The code can be long, but you need it in order to debug. It is nicer to work with it in a file than a terminal. It is also easier to interpret gofmt errors with an editor providing file and line numbers.
Types ¶
This section is empty.